function qs(ele) {
    return document.querySelector(ele)
}

// 接口地址：https://www.apifox.cn/apidoc/shared-36f0cbc0-9064-44bc-850a-805e263bf494/api-25827426



axios.defaults.baseURL = 'http://124.223.14.236:3001/api'
async function fn() {
    const {
        data: res
    } = await axios.get('/city/province')
    console.log(res);
    let shengStr = res.data.map((item) => {
        return `<option value="${item.province}">${item.name}</option>`
    }).join('')
    console.log(shengStr);
    qs('#province').innerHTML = '<option value="">请选择省份</option>' + shengStr
    qs('#province').value = '34'
    const {
        data: city
    } = await axios.get('/city/city', {
        params: {
            provinceCode: '34'
        }
    })
    console.log(city);
    let shiStr = city.data.map(item => {
        return `<option value="${item.city}">${item.name}</option>`
    }).join('')
    qs('#city').innerHTML = '<option value="">请选择城市</option>' + shiStr
    qs('#city').value = '01'
    const {
        data: area
    } = await axios.get('/city/area', {
        params: {
            provinceCode: '34',
            cityCode: '01',
        }
    })
    console.log(area);
    let quStr = area.data.map(item => {
        return `<option value="${item.area}">${item.name}</option>`
    }).join('')
    qs('#county').innerHTML = '<option value="">请选择区县</option>' + quStr
    qs('#county').value = '02'
}
fn()
qs('#province').addEventListener('click', async function () {
    console.log(this.value);
    const {
        data: {
            data: cityData
        }
    } = await axios.get('/city/city', {
        params: {
            provinceCode: this.value,

        }
    })
    let cityStr = cityData.map(item => {
        return `<option value="${item.city}">${item.name}</option>`
    }).join('')
    qs('#city').innerHTML = '<option value="">请选择城市</option>' + cityStr
    qs('#county').innerHTML = '<option value="">请选择区县</option>'
})



qs('#city').addEventListener('click', async function () {
    console.log(this.value);
    const {
        data: {
            data: areaData
        }
    } = await axios.get('/city/area', {
        params: {
            provinceCode: qs('#province').value,
            cityCode: this.value
        }
    })
    let areaStr = areaData.map(item => {
        return `<option value="${item.area}">${item.name}</option>`
    }).join('')
    qs('#county').innerHTML = '<option value="">请选择区县</option>' + areaStr
})
